package com.ming.multifunction.mq;

import com.ming.multifunction.contant.BiMqConstant;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;


import java.util.HashMap;
import java.util.Map;

/**
 * @author LiSuiMing
 * 创建测试测序用到的交换机和队列 (仅执行一次)
 */
public class BiMqInitMain {
    public static void main(String[] args) {
        try {
            ConnectionFactory factory = new ConnectionFactory();
            // 设置 rabbitmq 对应的信息
            factory.setHost("47.113.195.180");
            factory.setUsername("admin");
            factory.setPassword("admin");

            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();

            String demoExchange = BiMqConstant.BI_EXCHANGE_NAME;
            channel.exchangeDeclare(demoExchange, "direct");


            Map<String, Object> arguments = new HashMap<String, Object>();
            arguments.put("x-single-active-consumer", true);
//            ch.queueDeclare("my-queue", false, false, false, arguments);
            // 创建队列，分配一个队列名称：小紫
            String queueName = BiMqConstant.BI_QUEUE_NAME;
            channel.queueDeclare(queueName, true, false, false, arguments);
            channel.queueBind(queueName, demoExchange, BiMqConstant.BI_ROUTINGKEY);

        } catch (Exception e) {

        }
    }

}